package com.suray.basic.wcs.plc.pojo.oper.single.lifter;

import com.suray.basic.wcs.plc.config.resolver.PlcAnnotation;
import com.suray.basic.wcs.plc.core.PlcOffset;
import com.suray.basic.wcs.plc.enums.Location;
import com.suray.basic.wcs.plc.enums.PlcDeviceType;
import com.suray.basic.wcs.plc.pojo.DeviceBase;
import com.suray.basic.wcs.utils.Coord;

import java.io.IOException;

public class LifterSystemOper extends DeviceBase {
    /**
     * WCS下发输送主站编号
     */
    private static final PlcOffset MAIN_STATION = new PlcOffset(0, null);

    /**
     * 校验位
     */
    private static final PlcOffset CHECK = new PlcOffset(3, null);


    public LifterSystemOper(PlcDeviceType plcDeviceType, int startNo, String deviceName, int deviceNo, Coord coord,
                            Location location, Coord lockLocation, long deviceId, Integer gridzMax,
                            Integer gridzRelative, int plcId) {
        super(plcDeviceType, startNo, deviceName, deviceNo, coord, location, lockLocation, deviceId, gridzMax,
                gridzRelative, plcId);
    }

    /**
     * WCS下发输送主站编号
     * @throws IOException
     */
    @PlcAnnotation(value = "WCS下发输送主站编号")
    public void setMainStation() throws IOException {
        oper("WCS下发输送主站编号", this.getClass(), getStartNo() + MAIN_STATION.getAddressOffset(),
                10, 1);
    }

    public boolean isMainStation() {
        return readPlc(MAIN_STATION) == 1;
    }

    /**
     * 获取校验位
     * @return
     */
    public int getCheck() {
        return readPlc(CHECK);
    }
}
